package SpringMVC.nota;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(value = "/nota")
public class NotaController {

	@Autowired
	private NotaRepository nRepository;

	@RequestMapping(value = "/listar")
	public void listar(ModelMap modelMap) {

		List<Nota> notas = nRepository.findAll();
		modelMap.addAttribute("listaNotas", notas);
	}

	@RequestMapping(value = "/crear", method = RequestMethod.POST)
	public String crear(@ModelAttribute NotaForm notaForm) {
		nRepository.save(notaForm.createNota());
		return "redirect:/nota/listar";
	}

}
